# -*- coding: utf-8 -*-
import random
import time

from _datetime import datetime, timedelta

from Ini_utils import UtilIni


class CommonUtil:
    @staticmethod
    def make_chg_sn():
        order_sn = ((datetime.now().strftime('%Y%m%d%H')) + str(int(time.time())))
        UtilIni().writeln(section='AutoStation', option="orderSn", value=order_sn)
        return order_sn

    @staticmethod
    def get_vin():
        return UtilIni().getvalue('AutoStation', 'vin')

    @staticmethod
    def make_swap_sn():
        order_sn = ((datetime.now().strftime('%Y%m%d%H')) + str(int(time.time())))
        UtilIni().writeln(section='AutoStation', option="orderSn", value=order_sn)
        return order_sn

    @staticmethod
    def get_order_sn():
        return UtilIni().getvalue('AutoStation', 'orderSn')

    @staticmethod
    def get_time_stamp():
        current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        return current_time

    @staticmethod
    def get_spot_code():
        baseCode = '100040001'
        spot_code = baseCode + "{:07d}".format(random.randint(1, 9999999))
        return spot_code

    @staticmethod
    def time_after_5_minutes():
        current_time = datetime.now()
        time_after_5_minutes = (current_time + timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:%S')
        return time_after_5_minutes

    @staticmethod
    def get_current_date():
        current_date = datetime.now().date()
        return str(current_date)

    @staticmethod
    def get_month_start():
        todayMidnight = time.strftime('%Y-%m-01 00:00:00', time.localtime())
        return todayMidnight

    @staticmethod
    def get_month_stop():
        todayOverTime = time.strftime('%Y-%m-31 23:59:59', time.localtime())
        return todayOverTime

    @staticmethod
    def get_spot_name():
        base_name = "ZDH测试桩"
        spot_name = base_name + str(random.randint(0, 999))
        return spot_name

    @staticmethod
    def get_chgStation_name():
        chgStation = "CDZ"
        chgStation = chgStation + str(random.randint(0, 999))
        return chgStation

    @staticmethod
    def get_exchange_name():
        name = 'HDZ' + str(random.randint(0, 999))
        return name

    @staticmethod
    def get_external_code():
        code = "{:06d}".format(random.randint(1, 999999))
        return code

    @staticmethod
    def get_yesterday_date():
        today = datetime.now()
        yesterday = (today - timedelta(days=1)).strftime('%Y-%m-%d')
        return yesterday

    @staticmethod
    def get_yesterday_datetime():
        today = datetime.now()
        yesterday = (today - timedelta(days=1)).strftime('%Y-%m-%d %H:%M:00')
        return yesterday

    @staticmethod
    def get_yesterday_after_5min():
        today = datetime.now()
        yesterday = today - timedelta(days=1)
        new_datetime = (yesterday + timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:00')
        return new_datetime

    @staticmethod
    def get_current_month():
        currentMonth = time.strftime('%Y-%m', time.localtime())
        return currentMonth

    @staticmethod
    def get_rateModelID():
        return UtilIni().getvalue('AutoStation', 'rateModelID')

    @staticmethod
    def get_spotRateModelID():
        return UtilIni().getvalue('AutoStation', 'spotRateModelID')

    @staticmethod
    def get_chgSwitch():
        return UtilIni().getvalue('AutoStation', 'chgSwitch')

    @staticmethod
    def get_startType():
        return UtilIni().getvalue('AutoStation', 'startType')

    @staticmethod
    def get_state():
        return UtilIni().getvalue('AutoStation', 'state')

    @staticmethod
    def get_chgid():
        return UtilIni().getvalue('AutoStation', 'chgid')

    @staticmethod
    def get_networkConn():
        return str(random.randint(0, 501))

    @staticmethod
    def get_external_code():
        return UtilIni().getvalue('AutoStation', 'stationNo')

    @staticmethod
    def get_spotCode():
        return UtilIni().getvalue('AutoStation', 'spotCode')

    @staticmethod
    def get_rfidCode():
        return UtilIni().getvalue('AutoStation', 'rfidCode')

    @staticmethod
    def get_plateNo():
        return UtilIni().getvalue('AutoStation', 'plateNo')

    @staticmethod
    def get_soc():
        return random.randint(60, 100)
